package chances.epg.ui.taglib.model.flow;

import chances.epg.ui.taglib.model.Rect;

@SuppressWarnings("serial")
public class FlowStatus implements java.io.Serializable {
	private int row;
	private int col;
	private int index;
	private int nextTop;
	private int nextLeft;
	private int colspace;
	private int rowspace;
	private boolean horizontal;
	private Rect parentRect;
	private boolean warp;
	private boolean grow;
	private int displayCount;

	public FlowStatus() {

		reset();

	}

	public void reset() {
		this.row = 0;
		this.col = 0;
		this.index = -1;
		this.nextLeft = 0;
		this.nextTop = 0;
		this.colspace = 0;
		this.colspace = 0;
		this.warp = true;
		this.grow = false;
		this.horizontal = true;
	}

	public Rect next(Rect rect) {
		Rect result = new Rect();
		rect.copyto(result);
		result.setLeft(nextLeft);
		result.setTop(nextTop);
		if (this.horizontal) {
			if ((nextLeft + rect.getWidth() +  rect.getLeft() >= parentRect.getWidth())
					&& this.warp) {
				nextLeft = 0;
				row++;
				nextTop = rect.getHeight() + nextTop + this.rowspace;
			} else {
				nextLeft = this.nextLeft + colspace + rect.getLeft() + rect.getWidth() ;
			}
		} else {
			if (nextTop + rect.getHeight() + rect.getTop()   >= parentRect.getHeight()
					&& this.warp) {
				nextTop = 0;
				col++;
				nextLeft =rect.getWidth()+  nextLeft + this.colspace;
			} else {
				nextTop = this.nextTop  + rowspace  +  rect.getTop() + rect.getHeight();
			}
		}
		return result;
	}

	public int getNextTop() {
		return nextTop;
	}

	public void setNextTop(int nextTop) {
		this.nextTop = nextTop;
	}

	public int getNextLeft() {
		return nextLeft;
	}

	public void setNextLeft(int nextLeft) {
		this.nextLeft = nextLeft;
	}

	public int getRow() {
		return row;
	}

	public void setRow(int row) {
		this.row = row;
	}

	public int getCol() {
		return col;
	}

	public void setCol(int col) {
		this.col = col;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	/**
	 * 
	 */
	public class RowInfo implements java.io.Serializable {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		int end;
		int begin;
		int length;

		public int getEnd() {
			return end;
		}

		public void setEnd(int end) {
			this.end = end;
		}

		public int getBegin() {
			return begin;
		}

		public void setBegin(int begin) {
			this.begin = begin;
		}

		public int getLength() {
			return length;
		}

		public void setLength(int length) {
			this.length = length;
		}

	}

	public int getColspace() {
		return colspace;
	}

	public void setColspace(int colspace) {
		this.colspace = colspace;
	}

	public int getRowspace() {
		return rowspace;
	}

	public void setRowspace(int rowspace) {
		this.rowspace = rowspace;
	}

	public boolean isHorizontal() {
		return horizontal;
	}

	public void setHorizontal(boolean horizontal) {
		this.horizontal = horizontal;
	}

	public Rect getParentRect() {
		return parentRect;
	}

	public void setParentRect(Rect parentRect) {
		this.parentRect = parentRect;
	}

	public boolean getWarp() {
		return warp;
	}

	public void setWarp(boolean warp) {
		this.warp = warp;
	}

	public boolean getGrow() {
		return grow;
	}

	public void setGrow(boolean grow) {
		this.grow = grow;
	}

	public int getDisplayCount() {
		return displayCount;
	}

	public void setDisplayCount(int displayCount) {
		this.displayCount = displayCount;
	}
}
